#ifndef REMOTE_TREE_MODEL_H
#define REMOTE_TREE_MODEL_H

#include <QtCore>
#include <QFileSystemModel>
#include "common.h"

class RemoteTreeModel;

class RemoteTreeNode : public QModelIndex {
	friend class RemoteTreeModel;
public:
	RemoteTreeNode(const QString &_data, RemoteTreeNode *_parent = 0);

	RemoteTreeNode add_child(const QString &_data);

	uint num_children () const;

	RemoteTreeNode child(uint i) const;

	~RemoteTreeNode();

	bool operator == (RemoteTreeNode &rtn);
	bool operator != (RemoteTreeNode &rtn);

	static QVariant extract_data (const QModelIndex &index);

private:
	static RemoteTreeNode* cast_model_index (const QModelIndex &index);

	QString data;
	RemoteTreeNode *parent;
	QList<RemoteTreeNode*> children;
};

class RemoteTreeModel : private QAbstractItemModel {
public:
	QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
	QModelIndex parent(const QModelIndex &child) const;
	int rowCount(const QModelIndex &parent) const;
	int columnCount(const QModelIndex &parent) const;
	QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;

	bool operator == (const RemoteTreeModel &rtm);
	bool operator != (const RemoteTreeModel &rtm);

	static RemoteTreeModel* construct_from_QFileSystemModel (const QFileSystemModel &fsm);

private:
	QScopedPointer<RemoteTreeNode> root_node;
};

#endif // REMOTE_TREE_MODEL_H
